<?php

namespace common\models\c2\entity;

use common\components\AttachmentBehavior;
use cza\base\models\statics\ImageSize;
use Yii;

/**
 * This is the model class for table "{{%vip}}".
 *
 * @property integer $id
 * @property integer $type
 * @property string $label
 * @property string $price
 * @property string $ext
 * @property integer $position
 * @property integer $status
 * @property string $created_at
 * @property string $updated_at
 */
class Vip extends \cza\base\models\ActiveRecord
{

    use \common\traits\AttachmentTrait;

    public function fields()
    {
        return [
            'id',
            'status',
            'cover' => function ($model) {
                return $model->getInitialPreviewUrls('cover', ImageSize::ORGINAL);
            },
        ];
    }

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%vip}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['price'], 'number'],
            [['ext'], 'string'],
            [['position'], 'integer'],
            [['created_at', 'updated_at'], 'safe'],
            [['type'], 'string', 'max' => 3],
            [['label'], 'string', 'max' => 255],
            [['status'], 'string', 'max' => 4],
        ];
    }

    public function behaviors()
    {
        return [
            'attachmentsBehavior' => [
                'class' => AttachmentBehavior::className(),
                'attributesDefinition' => [
                    'cover' => [
                        'class' => \common\models\c2\entity\EntityAttachmentImage::className(),
                        'validator' => 'image',
                        'rules' => [
                            'maxFiles' => 1,
                            'uploadRequired' => Yii::t('app.c2', 'Photo must upload.'),
                            // 'skipOnEmpty' => false,
                            // 'skipOnError' => false,
                            'extensions' => Yii::$app->params['config']['upload']['imageWhiteExts'],
                            // 'extensions' => ['jpg'],
                            'maxSize' => Yii::$app->params['config']['upload']['maxFileSize'],
                            // 'maxSize' => '2048',
                        ]
                    ]
                ]
            ],

        ]; // TODO: Change the autogenerated stub
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app.c2', 'ID'),
            'type' => Yii::t('app.c2', 'Type'),
            'label' => Yii::t('app.c2', 'Label'),
            'price' => Yii::t('app.c2', 'Price'),
            'ext' => Yii::t('app.c2', 'Ext'),
            'position' => Yii::t('app.c2', 'Position'),
            'status' => Yii::t('app.c2', 'Status'),
            'created_at' => Yii::t('app.c2', 'Created At'),
            'updated_at' => Yii::t('app.c2', 'Updated At'),
        ];
    }

    /**
     * @inheritdoc
     * @return \common\models\c2\query\VipQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new \common\models\c2\query\VipQuery(get_called_class());
    }
    
    /**
    * setup default values
    **/
    public function loadDefaultValues($skipIfSet = true) {
        parent::loadDefaultValues($skipIfSet);
    }

}
